//
//  ZZMainTabBarController.swift
//  enjoy
//
//  Created by 张鹏 on 16/6/7.
//  Copyright © 2016年 ZP. All rights reserved.
//

import UIKit

class ZZMainTabBarController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        //设置UINavigationBar title的字体和颜色
        let titleTextAttributes :[String : AnyObject] = [NSFontAttributeName : UIFont(name: "Helvetica", size: 17) as! AnyObject , NSForegroundColorAttributeName : UIColor.whiteColor() as AnyObject]
        UINavigationBar.appearance().titleTextAttributes = titleTextAttributes
        
        //navigationBar的默认背景颜色
        UINavigationBar.appearance().barTintColor = UIColor.blackColor()
        
        addChildViewControllers()
    }
    
    func addChildViewControllers() {
      
        addChildViewControllers(ZZAllCityViewController(), title: "全城精选", imageName: "tab_home")
        addChildViewControllers(ZZAllCountryViewController(), title: "全国送", imageName: "tab_express")
         addChildViewControllers(ZZShoppingCarViewController(), title: "购物车", imageName: "tab_cart")
        addChildViewControllers(ZZMineViewController(), title: "我的", imageName: "tab_me")
    }
    
    func addChildViewControllers(vc: UIViewController, title : String, imageName : String ) {
        
        vc.title = title
        vc.tabBarItem.image = UIImage(named: imageName)
        

        vc.tabBarItem.titlePositionAdjustment = UIOffset(horizontal: 0, vertical: -3)

        vc.tabBarItem.selectedImage = UIImage(named: imageName+"_selected")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)

        vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName : UIColor.blackColor()], forState: UIControlState.Selected)

        let nav = UINavigationController(rootViewController: vc)
        
        addChildViewController(nav)
    }
    
}
